<template>
  <div class="app-home">
    <Homeheader />
    <div class="home-banner">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item v-for="item in HomeBannerlist" :key="item.id">
          <img :src="item.image_url" alt="" class="home-img">
        </van-swipe-item>
      </van-swipe>
    </div>
    <div class="home-channel">
      <van-grid :column-num="5" :border="false">
        <van-grid-item v-for="item in ChannelList" :key='item.id'
          @click="$router.push({ name: 'clickcate', query: { name: item.name } })">
          <van-image :src="item.icon_url" />
          <p>{{ item.name }}</p>
        </van-grid-item>
      </van-grid>
    </div>
    <div class="home-brandList">
      <h1 class="brandList-title">品牌制造商提供</h1>
      <div class="brandlist-content">
        <div class="brandlist-content-item" v-for="item in brandList" :key="item.id"
          @click="$router.push({ name: 'brdetl', query: { id: item.id } })">
          <div class="item-info">
            <div class="item-name">{{ item.name }}</div>
            <p class="item-price">{{ item.floor_price }}元起</p>
          </div>
          <img :src="item.new_pic_url" alt="" class="item-img">
        </div>
      </div>
    </div>
    <div class="home-newGoods" @click="$router.push({ name: 'hotnew', query: { name: '新品首发' } })"></div>
    <div class="home-newGoods-list">
      <div class="newGoods-list-item" v-for="item in newGoodsList" :key="item.id"
        @click="$router.push({ name: 'detial', params: { id: item.id } })">
        <img :src="item.list_pic_url" alt="" class="newGoods-img">
        <div class="newGoods-name">{{ item.name }}</div>
        <div class="newGoods-brief">{{ item.goods_brief }}</div>
        <div class="newGoods-price">￥{{ item.retail_price }}</div>
      </div>
    </div>
    <div class="home-hotGoods" @click="$router.push({ name: 'hotnew', query: { name: '人气推荐' } })"></div>
    <div class="home-newGoods-list">
      <div class="newGoods-list-item" v-for="item in hotGoodsList" :key="item.id"
        @click="$router.push({ name: 'detial', params: { id: item.id } })">
        <img :src="item.list_pic_url" alt="" class="newGoods-img">
        <div class="newGoods-name">{{ item.name }}</div>
        <div class="newGoods-brief">{{ item.goods_brief }}</div>
        <div class="newGoods-price">￥{{ item.retail_price }}</div>
      </div>
    </div>
    <div class="home-topicList">
      <h1 class="topicList-title">专题精选</h1>
      <div class="topicList-content">
        <div class="topicList-content-item" v-for="item in topicList " :key="item.id"
          @click="$router.push({ name: 'topdet', query: { id: item.id } })">
          <img :src="item.item_pic_url" alt="" class="item-img">
          <div class="item-info">
            <div class="info-name">{{ item.title }}</div>
            <div class="info-price">{{ item.price_info }}元起</div>
          </div>
          <div class="item-bottom">{{ item.subtitle }}</div>
        </div>
      </div>
    </div>
    <GoodsList v-for="item in newCategoryList" :key="item.id" :data="item" />
  </div>
</template> 

<script setup lang="ts">
import Homeheader from './Homeheader.vue';
import GoodsList from '@/components/Goods/GoodsList.vue'
import { ref, onMounted, provide } from 'vue'
import { getHomeDataApi } from '@/api/home'
import { LS_Pro } from '@/util/storage'

// 这是轮播图的数据
const HomeBannerlist = ref<HomeNs.IbannerData[]>([])
// 这里是Channel数据
const ChannelList = ref<HomeNs.IChannelData[]>([])
// 这里是品牌商的数据
const brandList = ref<HomeNs.IbrandListData[]>([])
// 这里是新品列表数据
const newGoodsList = ref<HomeNs.InewGoodsData[]>([])
// 这里是热卖的列表数据
const hotGoodsList = ref<HomeNs.IhotGoodsData[]>([])
// 这里是专题列表数据
const topicList = ref<HomeNs.ItopicListData[]>([])
// 这里是首页商品的数据
const newCategoryList = ref<HomeNs.InewCategoryListData[]>([])
// 这是获取首页数据的逻辑
const getHomeData = async () => {
  let res = await getHomeDataApi()
  // 这是轮播图数据
  HomeBannerlist.value = res.banner

  // 这是Channel数据
  ChannelList.value = res.channel
  // 这里是品牌商的数据
  brandList.value = res.brandList
  LS_Pro.set('brandList', brandList.value)
  // 这里是新品商品列表
  newGoodsList.value = res.newGoods
  LS_Pro.set('newGoodsList', newGoodsList.value)
  // 这里是人气商品列表
  hotGoodsList.value = res.hotGoods
  LS_Pro.set('hotGoodsList', hotGoodsList.value)
  // 这里是专题商品列表
  topicList.value = res.topicList
  LS_Pro.set('topicList', topicList.value)
  // 这里是首页商品的列表
  newCategoryList.value = res.newCategoryList
  LS_Pro.set('newCategoryList', newCategoryList.value)
}
onMounted(() => {
  getHomeData()
})
</script>

<style   lang="scss">
.app-home {
  height: 100%;
  overflow-x: hidden;

  // 这里是轮播图
  .home-banner {
    height: 1.71rem;
    width: 3.567rem;
    padding: 11px 9.5px 0px 9.5px;
    background: #fff;


    .my-swipe {
      height: 100%;
      width: 100%;
      background-color: #39a9ed;

      .van-swipe-item {
        height: 100%;
        width: 100%;
        color: #fff;
        font-size: 20px;
        line-height: 1.71rem;
        text-align: center;

        .home-img {
          display: block;
          width: 100%;
          height: 100%;
        }

      }
    }
  }

  // 这里是小分类
  .home-channel {
    padding: 13px 0;
    background: #fff;

    .van-grid-item {
      font-size: 13px;
      color: #666666;

      .van-image {
        width: 0.35rem;
        height: 0.35rem;
      }
    }

  }

  // 这里是品牌商
  .home-brandList {
    width: 3.57rem;
    height: 2.85rem;
    padding: 0 9.5px;
    margin-top: 9.5px;
    background: #fff;
    overflow: hidden;

    .brandList-title {
      font-size: 19px;
      color: #333333;
      text-align: center;
      margin: 20px 0;
      line-height: 1;
      font-weight: 500;
    }

    .brandlist-content {
      width: 100%;
      height: 2rem;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;

      .brandlist-content-item {
        width: 1.75rem;
        height: 0.98rem;
        overflow: hidden;
        // background: red;
        position: relative;

        .item-info {
          position: relative;
          margin: 16.5px 0 0 11.5px;
          z-index: 2;

          .item-name {
            font-size: 15px;
            color: #333333;
            line-height: 1;
          }

          .item-price {
            font-size: 12px;
            color: #999999;
            margin-top: 5px;
            line-height: 1;
          }
        }

        .item-img {
          position: absolute;
          width: 100%;
          height: 100%;
          top: 0;
          left: 0;
          z-index: 1;
        }

      }
    }
  }

  // 这里是新品首发标题
  .home-newGoods {
    width: 3.35rem;
    height: 1.21rem;
    margin: 10px auto;
    background: url('http://jinglins.gitee.io/bufan-tesco-mall/assets/new-product-pic-ab17c35e.png') no-repeat center center /100% 100%;
  }

  // 这里是新品首发列表
  .home-newGoods-list {
    height: 2.45rem;
    overflow: auto;
    background: #fff;
    display: flex;

    .newGoods-list-item {
      width: 1.48rem;
      height: 1.96rem;
      display: flex;
      flex-direction: column;
      flex-wrap: nowrap;
      align-items: center;
      flex-shrink: 0;
      border-right: 1px solid rgba(151, 151, 151, .2);
      box-sizing: border-box;
      margin-top: 30px;

      .newGoods-img {
        width: 1.27rem;
        height: 1.27rem;
      }

      .newGoods-name {
        width: 1.05rem !important;
        height: 20px;
        white-space: nowrap;
        width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        font-style: 15px;
        line-height: 1;
        color: #333333;
      }

      .newGoods-brief {
        width: 1.05rem !important;
        height: 16px;
        white-space: nowrap;
        width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        line-height: 1;
        font-size: 12px;
        color: #999999;
      }

      .newGoods-price {
        margin-top: 5px;
        margin-right: 60px;
        color: #9e4242;
        font-size: 12px;
      }
    }
  }

  .home-hotGoods {
    width: 3.35rem;
    height: 1.21rem;
    margin: 10px auto;
    background: url('http://jinglins.gitee.io/bufan-tesco-mall/assets/hot-recom-pic-743969c3.png') no-repeat center center /100% 100%;
  }

  .home-topicList {
    width: 3.56rem;
    height: 3.13rem;
    padding: 0 9.5px;
    margin-top: 10px;
    background: #fff;
    overflow: hidden;

    .topicList-title {
      font-size: 19px;
      color: #333333;
      text-align: center;
      line-height: 1;
      margin: 20px 0;
      font-weight: normal;
    }

    .topicList-content {
      height: 2.15rem;
      width: 100%;
      overflow: auto;
      display: flex;

      .topicList-content-item {
        width: 2.78rem;
        height: 100%;
        display: flex;
        flex-direction: column;
        flex-wrap: wrap;
        // background: red;
        margin-right: 10px;
        flex-shrink: 0;
        box-sizing: border-box;

        .item-img {
          width: 100%;
          height: 1.55rem;
        }

        .item-info {
          display: flex;
          justify-content: space-between;
          margin-top: 10px;

          .info-name {
            font-size: 15px;
            color: #333333;
            line-height: 1;
          }

          .info-price {
            font-size: 12px;
            color: #9e4242;
            line-height: 1;
          }
        }

        .item-bottom {
          font-size: 12px;
          color: #999999;
          margin-top: 6px;
          line-height: 1;
          white-space: nowrap;
          width: 1.08rem;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
    }
  }
}</style>